home *** CD-ROM | disk | FTP | other *** search
/ CU Amiga Super CD-ROM 14 / CU Amiga Magazine's Super CD-ROM 14 (1997)(EMAP Images)(GB)(Track 1 of 3)[!][issue 1997-09].iso / CUCD / Programming / GMS / Source / C / Blitter / BounceLine.c < prev    next >
Encoding:
C/C++ Source or Header  |  1997-05-04  |  2.0 KB  |  87 lines

  1. /*
  2. ** Name:      BounceLine.c
  3. ** Author:    Paul Manias
  4. ** Copyright: DreamWorld Productions, 1997.
  5. ** Doc:       Line bouncing demo that works on a screen of any type of
  6. **            dimensions as specified by the user in GMSPrefs.
  7. **
  8. ** To compile with SAS/C
  9. **
  10. **  1> sc BounceLine.c link startup=LIB:gms.o data=far
  11. **
  12. */
  13.  
  14. #include <proto/games.h>
  15.  
  16. extern struct GMSBase *GMSBase;
  17. ULONG _XCEXIT = NULL;
  18. ULONG PREFSNAME = DEFAULT;
  19.  
  20. void main(void)
  21. {
  22.   struct GameScreen *GameScreen;
  23.   ULONG palette[] = { 0x000000,0x80f0f0 };
  24.   ULONG mousestat;
  25.   int sx,sy,ex,ey;
  26.   int dsx,dsy,dex,dey;
  27.  
  28.   if (AllocBlitter() == NULL) {
  29.     if (GameScreen = AddScreenTags(TAGS_GAMESCREEN,NULL,
  30.        GSA_Palette,palette,
  31.        GSA_AmtColours,2,
  32.        GSA_Attrib,DBLBUFFER,
  33.        TAGEND)) {
  34.  
  35.        sx = SlowRandom(GameScreen->ScrWidth);  dsx = -1;
  36.        sy = SlowRandom(GameScreen->ScrHeight); dsy = 2;
  37.        ex = SlowRandom(GameScreen->ScrWidth);  dex = 3;
  38.        ey = SlowRandom(GameScreen->ScrHeight); dey = 1;
  39.  
  40.        ShowScreen(GameScreen);
  41.  
  42.        do
  43.        {
  44.          ClrScreen(GameScreen,BUFFER2);
  45.          mousestat = ReadMouse(JPORT1);
  46.          sx += dsx;
  47.          sy += dsy;
  48.          ex += dex;
  49.          ey += dey;
  50.  
  51.          if(sx<0) { sx = 0; dsx = -(dsx); }
  52.          if(sy<0) { sy = 0; dsy = -(dsy); }
  53.          if(ex<0) { ex = 0; dex = -(dex); }
  54.          if(ey<0) { ey = 0; dey = -(dey); }
  55.  
  56.          if(sx>GameScreen->ScrWidth-1) {
  57.            sx  = GameScreen->ScrWidth-1;
  58.            dsx = -(dsx);
  59.          }
  60.  
  61.          if(sy>GameScreen->ScrHeight-1) {
  62.            sy  = GameScreen->ScrHeight-1;
  63.            dsy = -(dsy);
  64.          }
  65.  
  66.          if(ex>GameScreen->ScrWidth-1) {
  67.            ex  = GameScreen->ScrWidth-1;
  68.            dex = -(dex);
  69.          }
  70.  
  71.          if(ey>GameScreen->ScrHeight-1) {
  72.            ey  = GameScreen->ScrHeight-1;
  73.            dey = -(dey);
  74.          }
  75.  
  76.          DrawUCLine(GameScreen,BUFFER2,sx,sy,ex,ey,1);
  77.          WaitVBL();
  78.          SwapBuffers(GameScreen);
  79.        } while (!(mousestat & MB_LMB));
  80.  
  81.     DeleteScreen(GameScreen);
  82.     }
  83.   FreeBlitter();
  84.   }
  85. }
  86.  
  87.